package com.bn.commerce.order;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

import com.bn.userprofile.BNProfileTools;
import com.bn.util.BNConstants;

import atg.commerce.CommerceException;
import atg.commerce.profile.CommerceProfileTools;
import atg.commerce.profile.CommercePropertyManager;
import atg.core.util.Address;
import atg.core.util.ResourceUtils;
import atg.core.util.StringUtils;
import atg.projects.store.logging.LogUtils;
import atg.projects.store.order.StoreOrderTools;
import atg.repository.RepositoryException;
import atg.repository.RepositoryItem;
import atg.servlet.ServletUtil;

public class BNOrderTools extends StoreOrderTools implements BNConstants {

	public String saveAddressToAddressBook(RepositoryItem pProfile,
			Address pAddress, String pNickName, boolean isMakeDefault)
			throws CommerceException {

		String nickName =pNickName;
		vlogDebug("BNOrderTools.saveAddressToAddressBook() - begin");
		BNProfileTools profileTools = (BNProfileTools) getProfileTools();
		if (StringUtils.isEmpty(nickName)) {
			nickName = profileTools.getUniqueShippingAddressNickname(pAddress,
					pProfile, null);
		}
		boolean result=true;
		try {
			result = copyAddressToAddressBook(pProfile, pAddress, nickName);
		} catch (RuntimeException e1) {
			isMakeDefault=false;
		}
		if (!(result)) {
			String msg = ResourceUtils.getMsgResource(
					"errorCreatingShippingAddress",
					"atg.commerce.order.purchase.UserMessages",
					getResourceBundle(ServletUtil.getUserLocale()));
			throw new CommerceException(msg);
		}
		vlogDebug("BNOrderTools.saveAddressToAddressBook()- end");
		return nickName;
	}
}
